package com.cskaoyan.controller;


import com.cskaoyan.bean.Topic;
import com.cskaoyan.bean.vo.AdminAdForListDataBean;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.AdminTopicService;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/topic")
public class AdminTopicController {

    @Autowired
    AdminTopicService topicService;


    @RequestMapping("list")
    public BaseRespVo list(Integer page, Integer limit, String title, String subtitle, String sort, String order){
        AdminAdForListDataBean<Topic> result = topicService.queryTopics(page, limit, title, subtitle, sort, order);
        return BaseRespVo.ok(result);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Topic topic) {
        Integer result = topicService.addTopic(topic);
        return result == 1 ? BaseRespVo.ok(topic) : BaseRespVo.fail();
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Topic topic) {
        Integer result = topicService.updateTopic(topic);
        return result == 1 ? BaseRespVo.ok(topic) : BaseRespVo.fail();
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Topic topic) {
        Integer result = topicService.deleteTopic(topic);
        return result == 1 ? BaseRespVo.ok(): BaseRespVo.fail();
    }
}
